package com.py.comment.controller;

import com.py.comment.service.CommentService;
import com.py.model.common.dtos.ResponseResult;
import com.py.model.moment.dtos.CommentDto;
import com.py.model.moment.dtos.CommentLikeDto;
import com.py.model.moment.dtos.CommentSaveDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author pengy
 * @create 2022-11-16 16:57
 */
@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 发表评论,保存到MongoDb
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody CommentSaveDto dto){
        commentService.saveToMongo(dto);
        return ResponseResult.okResult(null);
    }

    /**
     * 加载评论列表 分页展示
     * @return
     */
    @PostMapping("/load")
    public ResponseResult loadPage(@RequestBody CommentDto commentDto){
        return commentService.loadPage(commentDto);
    }


    /**
     * 点赞评论或者取消点赞
     * @param commentLikeDto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult like(@RequestBody CommentLikeDto commentLikeDto) {

        return commentService.like(commentLikeDto);
    }
}
